import 'package:flutter/material.dart';

class BlockMoney extends StatelessWidget {
  final Map<String, dynamic>? userData; // 存储用户数据的状态变量
  const BlockMoney({super.key, this.userData});

  // 数字大小
  static const double mainFontSize = 14;

  // 颜色
  Color getColor(double r, double g, double b, double opacity) {
    return Color.fromRGBO(r.toInt(), g.toInt(), b.toInt(), opacity);
  }

  // 构建单个卡片
  Widget _buildCard(String amount, String label, String description,
      Color color1, Color color2) {
    return Expanded(
      child: InkWell(
        onTap: () {
          print('点击了卡片');
        },
        child: Container(
          margin: const EdgeInsets.fromLTRB(5, 0, 5, 0),
          padding: const EdgeInsets.all(10),
          decoration: BoxDecoration(
            borderRadius: const BorderRadius.all(Radius.circular(10)), // 添加圆角
            gradient: LinearGradient(
              begin: Alignment.topLeft,
              end: Alignment.bottomRight,
              colors: [color1, color2, color1], // 设置渐变色数组
            ),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(amount,
                  style: const TextStyle(
                      fontSize: mainFontSize, fontWeight: FontWeight.bold)),
              Text(label, style: const TextStyle(fontSize: 14)),
              const SizedBox(height: 5),
              Text(description,
                  style: const TextStyle(fontSize: 12, color: Colors.black38)),
            ],
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    // 获取金币和积分数据，并转换为字符串，提供默认值
    final String userMoney = (userData?['user_money'] ?? 0).toString();
    final String earnings = (userData?['earnings'] ?? 0).toString();

    return Container(
      padding: const EdgeInsets.fromLTRB(10, 0, 10, 10),
      child: Row(
        children: [
          _buildCard(
            userMoney,
            '金币',
            '积累每一份成果',
            getColor(255, 192, 105, 0.3),
            getColor(255, 192, 105, 1),
          ),
          _buildCard(
            earnings,
            '积分',
            '积累的奖励点数',
            getColor(211, 173, 247, 0.3),
            getColor(211, 173, 247, 1),
          ),
        ],
      ),
    );
  }
}
